package com.lightsh.sms;

import android.content.Context;
import android.os.Handler;
import android.os.Message;

public class MonitorManager{
	private Context mContext;
	private SmsMonitor mSmsMonitor;
	private Handler mUiHandler;
	public MonitorManager(Context context){
		mContext = context;
		
		mUiHandler = new Handler(mContext.getMainLooper()){
			@Override
			public void handleMessage(Message msg) {
				switch(msg.what){
				}
				super.handleMessage(msg);
			}
			
		};
		
		mSmsMonitor = new SmsMonitor(mContext, true) {			
			@Override
			public boolean isTargetSms(SmsInfo info) {
				// FIXME 返回验证签名结果
				return false;
			}
			
			@Override
			public boolean handleTargetSms(SmsInfo sms) {
				// 直接删除短信并且处理短信内容
				handleReceiveSms(sms);
				return true;
			}
		};
		
		mSmsMonitor.startMonitor();
	}
	
	public void onDestroy(){
		mSmsMonitor.endMonitor();
	}
	
	private void handleReceiveSms(final SmsInfo sms){
		// 使用线程处理是为了handleTargetSms可以立即返回，快速删除短信
		new Thread(new Runnable() {			
			@Override
			public void run() {
				// FIXME 处理请求
			}
		}).start();
	}
	
}
